<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .father {
            height: 200px;
            width: 200px;
            background-color: pink;
        }

        .son {
            height: 100px;
            width: 100px;
            background-color: purple;
        }
    </style>
</head>

<body>
    <div class="father">
        <div class="son"></div>
    </div>
    <script>
        // 捕获阶段
        // const fa = document.querySelector(".father");
        // const son = document.querySelector('.son');
        // document.addEventListener('click', function () {
        //     alert("我是爷爷");
        // }, true)
        // fa.addEventListener('click', function () {
        //     alert("我是爸爸");
        // }, true)

        // son.addEventListener('click', function () {
        //     alert("我是儿子");
        // }, true)
        // 冒泡阶段
        const fa = document.querySelector(".father");
        const son = document.querySelector('.son');
        document.addEventListener('click', function () {
            alert("我是爷爷");
        })
        fa.addEventListener('click', function () {
            alert("我是爸爸");
        })

        son.addEventListener('click', function (e) {
            alert("我是儿子");
            // 阻止事件流动
            e.stopPropagation();
        })


    </script>
</body>

</html>